package org.ngbx.demo.flink.dd.statistics;

import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.ngbx.demo.flink.dd.DeviceDataEvent;

import java.io.IOException;

public class DeviceDataEventDeserializationSchema implements DeserializationSchema<DeviceDataEvent> {
    // 注册JavaTimeModule，支持LocalDateTime字段的解析
    final private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public DeviceDataEvent deserialize(byte[] message) throws IOException {
        return objectMapper.readValue(message, DeviceDataEvent.class);
    }

    @Override
    public boolean isEndOfStream(DeviceDataEvent nextElement) {
        return false;
    }

    @Override
    public TypeInformation<DeviceDataEvent> getProducedType() {
        return TypeInformation.of(DeviceDataEvent.class);
    }
}
